package com.sgb.kjwl.view.ui.activity.material.hall;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentXufangFaqiBinding;
import com.sgb.jicai.entity.CentralizedMiningEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.view.ui.adapter.home.CentralizedMining2Adapter;
import com.sgb.kjwl.view.widget.PickAreaProCityPopWindow;
import com.sgb.link.view.widget.PickCityPopWindow;
import com.swgk.core.base.BaseFragment;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

/**
 * 需求大厅--需方集采
 */
public class LiceDataXufangFaQiFragment extends BaseFragment   {

    LiveDataXufangFaQiModle viewModel;
    FragmentXufangFaqiBinding binding;
    MutableLiveData<List<CentralizedMiningEntity>> list ;
    private CentralizedMining2Adapter centralizedMiningAdapter;
    private String jicaiMethod = "0";
//    public static final String JICAI_METHOD = "JiCaiMethod";
    private int jicaiType = 1;
//    public static final String JICAI_TYPE = "JiCaiType";
    private String keyWords = "";

    private boolean isLastPage;
    private boolean isTop = true;
    private PickSelectEntity all;
    //集采状态筛选
    private PickCityPopWindow statusPopWindow;//集采状态弹窗
    private List<PickSelectEntity> statusDatas = new ArrayList<>();
    private String statusNo = ""; //状态
    //省市--一二级筛选
    private PickAreaProCityPopWindow addrPopWindow;//省市选择弹窗
    private boolean addrIsChange;
    private List<PickSelectEntity> provinceDatas = new ArrayList<>();//省份数据
    private List<PickSelectEntity> cityDatas = new ArrayList<>();
    private String proNo = "";      //省
    private String cityNo = "";    //地区
    //商品类型---一二级筛选
    private PickAreaProCityPopWindow productTypesPopWindow;
    private PickCityPopWindow pickTimePopWindow; //截止时间
    private List<PickSelectEntity> timeDatas = new ArrayList<>();
    //时间
    private String timeNo="";
    private boolean typesIsChange;
    private List<PickSelectEntity> typesFirstDatas = new ArrayList<>();//省份数据
    private List<PickSelectEntity> typesSecondDatas = new ArrayList<>();
    private String firstTypeNo = "";
    private String secondTypeNo = "";
    public static final String FROM_WHERE="FROM_WHERE";

    /**
     *  jicaiMethod 集采方式（一级tab：0全部，1即报即采，2汇集采购,3企业专项,4集采锁价）
     *  jicaiType   集采类型（二级tab：0全部，1商品集采 2 机械集采 3 设备集采 4 劳务集采 5房产集采 6租赁集采）
     * @return
     */
    public static LiceDataXufangFaQiFragment newInstance(String fromWhere) {
        LiceDataXufangFaQiFragment fragment = new LiceDataXufangFaQiFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FROM_WHERE, fromWhere);
        fragment.setArguments(bundle);
        return fragment;
    }



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_xufang_faqi, container, false);
        viewModel= new ViewModelProvider(this).get(LiveDataXufangFaQiModle.class);
        list=viewModel.getList();
        list.observe(getViewLifecycleOwner(),centralizedMiningEntities ->{
            centralizedMiningAdapter.setDatas(centralizedMiningEntities);
        });
        if("1".equals(getArguments().get(FROM_WHERE))){
            binding.include.includeLayout.setVisibility(View.VISIBLE);
        }else{
            binding.include.includeLayout.setVisibility(View.GONE);
        }
        initView();
        initData();
        return binding.getRoot();
    }


    private void initView() {
        if (centralizedMiningAdapter == null) {
            centralizedMiningAdapter = new CentralizedMining2Adapter(getActivity(), null);
        }
        DividerItemDecoration divider = new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this.getContext(), R.drawable.shape_list_divide_factory_jc));
        binding.recyclerView.addItemDecoration(divider);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.recyclerView.setLayoutManager(layoutManager);
        //解决数据加载不完的问题
//        binding.recyclerView.setNestedScrollingEnabled(false);
        binding.recyclerView.setHasFixedSize(true);
        //解决数据加载完成后, 没有停留在顶部的问题
        binding.recyclerView.setFocusable(false);
        binding.recyclerView.setAdapter(centralizedMiningAdapter);

    }

    private void initData() {
        viewModel.getJiCaiList(proNo, cityNo, jicaiMethod, jicaiType, statusNo, firstTypeNo, secondTypeNo, keyWords, timeNo, false);
    }


    @Override
    protected boolean registerNet() {
        return false;
    }

    @Override
    protected void connectNetWork() {

    }

    @Override
    protected void disconnectNetWork() {

    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {

    }

    @Override
    public void onMultiClick(View v) {

    }
}
